package com.llt.lg.fractionPage;


import com.llt.bottomnavigationf.fraction.BaseFraction;
import com.llt.bottomnavigationf.util.RouterUtil;
import com.llt.lg.ResourceTable;
import com.llt.lg.slice.Routerdmeo2Slice;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;
import ohos.app.Context;

import java.util.HashMap;

public class MoneyList  extends BaseFraction {

    private Context context;
    private AbilitySlice abilitySlice;
    private DirectionalLayout component;//当前fraction 页面体
    private LayoutScatter scatter;
    private ComponentContainer container;
    private Intent intent;
    private DirectionalLayout body;
    public MoneyList(AbilitySlice abilitySlice) {
        this.abilitySlice = abilitySlice;

    }
    @Override
    protected Component onComponentAttached(LayoutScatter scatter, ComponentContainer container, Intent intent) {
        //获取fraction 体
        this.scatter=scatter;
        this.container = container;
        this.intent =intent;
        this.context = container.getContext();
        this.component =(DirectionalLayout)scatter.parse(ResourceTable.Layout_money_list, container, false);
        return component;
    }


    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        goPage();
    }
    public void goPage(){
        Text Id_gopage =(Text) abilitySlice.findComponentById(ResourceTable.Id_gopage);
        Id_gopage.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {

//                Method[] methods = MainAbility.class.getMethods();
//                try {
//                    Method setUIContent = MainAbility.class.getMethod("setUIContent");
//                    setUIContent.invoke(1);
//                } catch (NoSuchMethodException e) {
//                    e.printStackTrace();
//                } catch (IllegalAccessException e) {
//                    e.printStackTrace();
//                } catch (InvocationTargetException e) {
//                    e.printStackTrace();
//                }
//
//                Method[] methods1 = MainAbilitySlice.class.getMethods();


//                Intent intent = new Intent();
//                Operation operationBuilder = new Intent.OperationBuilder()
//                        .withDeviceId("")
//                        .withBundleName ( "com.llt.lg")//包名字
//                        .withAbilityName("com.llt.lg.routerDemo")
//
//                        .build()
//                        ;
//                intent.setOperation(operationBuilder);
//                IntentParams intentParams = new IntentParams();
//                intentParams.setParam("","");
//                intent.setParams(intentParams);
//                abilitySlice.startAbility(intent);
                Ability ability = abilitySlice.getAbility();
                try {
                    HashMap<String, Object> objectObjectHashMap = new HashMap<>();
                    objectObjectHashMap.put("nameId",1231);
                    RouterUtil.navigate(abilitySlice, new Routerdmeo2Slice());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
    @Override
    protected void onActive() {
        super.onActive();
    }

    @Override
    protected void onForeground(Intent intent) {
        System.out.println("MoneyList+onForeground");
        super.onForeground(intent);
    }

    @Override
    protected void onInactive() {
        super.onInactive();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    public int getUIContent() {
        return ResourceTable.Layout_money_list;
    }

    @Override
    public void initComponent() {

    }
}
